package br.unicap.curativotermosensor.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;



public class NotificacaoUtil {
	@SuppressWarnings("deprecation")
	@SuppressLint("NewApi")
	public static void create(Context contexto, CharSequence barraTexto, CharSequence titulo, CharSequence mensagem, 
			int icon, int id, Intent intent){
		PendingIntent pend = PendingIntent.getActivity(contexto, 0, intent, 0);
		Notification notificacao = null;
		int apiLevel = Build.VERSION.SDK_INT;
		Log.i("livro", "ApiLevel " + Integer.toString(apiLevel));
		if(apiLevel >=11){
			Builder build = new Notification.Builder(contexto)
											.setContentTitle(barraTexto)
											.setContentText(mensagem)
											.setSmallIcon(icon)
											.setContentIntent(pend);
			if(apiLevel >= 17){
				notificacao = build.build();
			} else {
				notificacao = build.getNotification();
			}

		} else {
			notificacao = new Notification(icon, barraTexto, System.currentTimeMillis());
			notificacao.setLatestEventInfo(contexto, titulo, mensagem, pend);
			notificacao.vibrate = new long[] { 200, 500, 200, 750 };
		}
		NotificationManager nm = (NotificationManager) contexto.getSystemService(Activity.NOTIFICATION_SERVICE);
		nm.notify(id, notificacao);
	}
	public static void cancela(Context contexto, int id){
		NotificationManager nm = (NotificationManager) contexto.getSystemService(Activity.NOTIFICATION_SERVICE);
		nm.cancel(id);
	}
}
